<?php 

	require_once "../common/PinSQL.obj";
	
	$username = $_SESSION['destuser'];
	$pinSQL = new PinSQL();
	
	$pinSQL->Query("SELECT * FROM members WHERE username='$username'");
	$row = $pinSQL->FetchNextRow();	
	
	$id = $row['id'];
	$firstname = $row['firstname'];
	$lastname = $row['lastname'];
	$email = $row['email'];
	$level = $row['level'];
	
	$pinSQL->Query("SELECT * FROM memberdata WHERE id='$id'");
	$row = $pinSQL->FetchNextRow();
	
	$sex = $row['sex'];
	$city = $row['city'];
	$state = $row['state'];
	$country = $row['country'];
	$website = $row['website'];
	$screenname = $row['screenname'];
	$phone = $row['phone'];
	$carrier = $row['carrier'];
	$cellnotify = $row['cellnotify'];
	$email_notify = $row['email_notify'];
	$birthday = $row['birthday'];
	
	$medium = nl2br($row['medium']);
	$influences = nl2br($row['influences']);
	$hobbies = nl2br($row['hobbies']);
	$interests = nl2br($row['interests']);
	$general = nl2br($row['general']);
	
	include "../browser_detect.php";
	
?>

<head>
	<link rel="stylesheet" type="text/css" href="profile_inner.css" />
</head>

<?php if ($browser=="ie6") { ?>
<style type="text/css">
.profile_box_header
{
	/* fix IE6 border rendering bug */
	border: 1px;
	padding-left: 4px;
	padding-right: 5px;
}
</style>
<?php } ?>

<script type="text/javascript" src="/common/highslide/highslide.js"></script>
<link rel="stylesheet" type="text/css" href="/common/highslide/highslide.css" />

<script type="text/javascript">    
    hs.graphicsDir = '/common/highslide/graphics/';
    hs.outlineType = 'outer-glow';
</script>

<?php $context = "profile"; include "otheruser_returnheader.php" ?>

<div class="padded_text">

<!-- display user notifications !-->

<?php
	$pinSQL->Query("SELECT * FROM messages WHERE touser='$username' AND isread='0' AND archived='0' ORDER BY date");
	
 	if ( $_SESSION['id'] == $id && $pinSQL->GetNumRows() )
 	{ // user has new message(s)
?>
<center>
	<img src="/img/icons/inbox_sm.png" />
	<a href="frame.php?page=inbox" target="_top"> <?php echo $pinSQL->GetNumRows(); ?> new unread message<?php echo ($pinSQL->GetNumRows() > 1) ? "s" : ""; ?></a>.
</center>
<?php }

 	$pinSQL->Query("SELECT * FROM buzz WHERE touser='$username' AND isread='0' ORDER BY date");
	
 	if ( $_SESSION['id'] == $id && $pinSQL->GetNumRows() )
 	{ // user has new buzz post(s)
?>
<center>
	<img src="/img/icons/update-new-buzz.png" />
	<a href="frame.php?page=profile&tab=buzz" target="_top"> <?php echo $pinSQL->GetNumRows(); ?> new unread buzz post<?php echo ($pinSQL->GetNumRows() > 1) ? "s" : ""; ?></a>.
</center>
<?php } ?>


<div class="horizontal_separation" style="clear: both;"></div>


<!-- display left column !-->
<div style="float: left; width: 275px;">

<!-- display user picture area !-->
	<div class="profile_box_border">
		<div class="padded_text">

			<div class="head2"><?php
	
	if (($firstname) OR ($lastname))
		echo $firstname . " " . $lastname;
	else
		echo $username;
	
		?></div>

			<div class="horizontal_separation"></div>
			<center>		
<?php
	$picurl = $row['picurl'];
	
	if ($picurl)
	{
		$imageSize = getimagesize("userData/$username/$picurl");
		
		if ($imageSize[0] <= 200)
		{
			$newWidth = $imageSize[0];
			$newHeight = $imageSize[1];
		} else {
			$heightFactor = $imageSize[1] / $imageSize[0];
			$newWidth = 200;
			$newHeight = $newWidth * $heightFactor;
		}
?>
			<img src="userData/<?php echo $username . "/" . $picurl; ?>" width="<?php echo $newWidth; ?>" height="<?php echo $newHeight; ?>" />	
<?php } else { ?>
			<img src="/img/icons/nopic.png" />	
<?php } ?>

<?php if ($_SESSION['id'] == $id) { ?>
			<span class="inline_button"> <a href="frame.php?page=editProfile">Edit</a> </span>
<?php } ?>
			</center>
			<div class="horizontal_separation"></div>
			
			Username:
			<span class="orangetext"><?php echo $username; ?></span>
			<div><a href="mailto: <?php echo $email; ?>"><?php echo $email; ?></div>
			<div class="horizontal_separation"></div>
			<img src="/img/arrow_red.gif" border=0/><a href="/members/frame.php?page=composemessage&touser=<?php echo $username; ?>" target="_top">Send a message to <?php echo ($firstname) ? $firstname : $username; ?></a>
<?php
	$pinSQL->Query("SELECT * FROM memberdata WHERE id='" . $_SESSION['id'] . "'");
	$row = $pinSQL->FetchNextRow();

	$taggedUsers = explode(",", $row['tagged_users']);
	$isTagged = FALSE;
	for ($i=0; $i<sizeof($taggedUsers); $i++)
	{
		if ($taggedUsers[$i] == $username)
		{ $isTagged = TRUE; }
	}
	
	if ($isTagged == FALSE)
	{
?>
			<br /><img src="/img/arrow_blue.gif" border=0/><a href="/members/do_action.php?actionname=taguser&user=<?php echo $username; ?>&referrer=taggedusers">Tag <?php echo ($firstname) ? $firstname : $username; ?></a>
<?php } ?>
		</div>
	</div>

	<div class="horizontal_separation" style="clear: both;"></div>
	<div class="horizontal_separation" style="clear: both;"></div>
	
	<div class="profile_box_header">
		Personal Info
<?php if ($_SESSION['username'] == $username) /*user's own profile*/ { ?>
		<span class="inline_button"> <a href="frame.php?page=editProfile#personal_info">Edit</a> </span>
<?php } ?>
	</div>
	
	<div class="profile_box_border">
		<div class="padded_text">
			<table>
<?php
		$hasContent = FALSE;
		
		//birthday
		$arr = explode('-', $birthday);
		$timestamp = mktime(0, 0, 0, $arr[1], $arr[2], $arr[0], -1);
		$today = time();
		if ( date('F j', $timestamp) == date('F j', $today) )
		{
			// today is the user's birthday
			$isBirthday = TRUE;
		}
		
		$prettydate = date('F j, Y', $timestamp);
		if ($birthday)
		{ echo "<tr><td><span class=\"orangetext\">Birthday:</span></td><td>$prettydate</td></tr>";
		$hasContent = TRUE; }
		
		//hometown
		$addr = $city;
		if ($state)
			if ($city)
				$addr.=", $state";
			else
				$addr = $state;
				
		if ($addr)
		{ echo "<tr><td><span class=\"orangetext\">Hometown:</span></td> <td>$addr</td></tr>";
		$hasContent = TRUE; }
		
		if ($country)
		{ echo "<tr><td></td> <td>$country</td></tr>";
		$hasContent = TRUE; }
		
		if ($sex)
		{
			echo "<tr><td><span class=\"orangetext\">Sex:</span></td> ";
			echo '<td><img src="/img/icons/';
			if ($sex == "m") echo "male"; else echo "female";
			echo '.gif"></td></tr>';
			$hasContent = TRUE;
		}
			
		if ($website)
		{ echo "<tr><td><span class=\"orangetext\">Website:</span></td> <td><a href=\"$website\">$website</td></tr>";
		$hasContent = TRUE; }
		
		if ($screenname)
		{ echo "<tr><td><span class=\"orangetext\">Screen Name:</span></td> <td>$screenname</td></tr>";
		$hasContent = TRUE; }
		
		if ($phone)
		{ echo "<tr><td><span class=\"orangetext\">Phone Number:</span></td> <td>$phone</td></tr>";
		$hasContent = TRUE; }
		
		if ($carrier)
		{
			echo "<tr><td><span class=\"orangetext\">Mobile Notifiation:</span></td> <td>";
			
			if ($cellnotify) {
				echo '<img src="/img/icons/cell_on.png" width="32" height="32" /> ';
				echo "On";
			} else {
				echo '<img src="/img/icons/cell_off.png" width="32" height="32" /> ';
				echo "Off";
			}
			
			echo " (";
			
			if ($carrier == "att")
				$carrier = "AT&T";
			
			echo $carrier;
			
			echo ")";
			echo "</td></tr>";
			
			$hasContent = TRUE;
		}
		
		echo "<tr><td><span class=\"orangetext\">E-mail Notifiation:</span></td> <td>";
		
		if ($email_notify) {
			echo '<img src="/img/icons/email.png" width="32" height="32" /> ';
			echo "On";
		} else {
			echo "Off";
		}
		echo "</td></tr></table>";
		
		if (!$hasContent)
		{ echo (($firstname) ? $firstname : $username) . " has not entered any personal info.";
		}

	?>
			
		</div>
	</div>
	
	<div class="horizontal_separation" style="clear: both;"></div>
	<div class="horizontal_separation" style="clear: both;"></div>
	
	<div class="profile_box_header">
		Artist Info
<?php if ($_SESSION['username'] == $username) /*user's own profile*/ { ?>
		<span class="inline_button"> <a href="frame.php?page=editProfile#artist_info">Edit</a> </span>
<?php } ?>
	</div>
	
	<div class="profile_box_border">
		<div class="padded_text">
<?php
		$hasContent = FALSE;
		
		if ($medium)
		{ echo "<div class=\"orangetext\">Preferred Medium:</div>$medium<div class=\"horizontal_separation\"></div>";
		$hasContent = TRUE; }
		
		if ($influences)
		{ echo "<div class=\"orangetext\">Influences:</div>$influences<div class=\"horizontal_separation\"></div>";
		$hasContent = TRUE; }
		
		if ($hobbies)
		{ echo "<div class=\"orangetext\">Hobbies:</div>$hobbies<div class=\"horizontal_separation\"></div>";
		$hasContent = TRUE; }
		
		if ($interests)
		{ echo "<div class=\"orangetext\">Interests:</div>$interests<div class=\"horizontal_separation\"></div>";
		$hasContent = TRUE; }
		
		if ($general)
		{ echo "<div class=\"orangetext\">General Information:</div>$general<div class=\"horizontal_separation\"></div>";
		$hasContent = TRUE; }
		
		if (!$hasContent)
		{ echo (($firstname) ? $firstname : $username) . " has not added any artist info.";
		}

?>
		</div>
	</div>
		
	<div class="horizontal_separation" style="clear: both;"></div>
	<div class="horizontal_separation" style="clear: both;"></div>
	
	<div class="profile_box_header">
		Recent Activity
<?php if ($_SESSION['username'] == $username) /*user's own profile*/ { ?>
		<!--<span class="inline_button"> <a href="frame.php?page=privacy">Edit</a> </span>!-->
<?php } ?>
	</div>
	
	<div class="profile_box_border">
		<div class="padded_text">
<?php

	$site_root = "../";
	$showUser = $username;
	include ($site_root . "gen_activity.php"); 

?>
		</div>
	</div>
	
</div>


<!-- display right column !-->
<div style="float: right; width: 275px;">

<?php if ($isBirthday) { ?>
	<div class="profile_box_border" style="border: 2px solid rgb(200, 70, 200);">
		<div class="padded_text">
			Today is <?php echo $pinSQL->GetFirstName( $_SESSION['username'] ); ?>'s birthday!
			<br /><a href="frame.php?page=profile&tab=buzz&user=<?php echo $username; ?>&write=1">Why not give <?php echo $pinSQL->GetObjectivePronoun( $_SESSION['username'] ); ?> a birthday buzz?</a>
		</div>
	</div>
	
	<div class="horizontal_separation"></div>
	<div class="horizontal_separation"></div>
<?php } ?>

<?php
	$quote = nl2br($pinSQL->GetUserdataField($username, "quote"));
if ($quote) { ?>

	<div class="profile_box_border">
		<div class="padded_text">
			<?php echo $quote; ?>
		</div>
	</div>
	
	<div class="horizontal_separation" style="clear: both;"></div>
	<div class="horizontal_separation" style="clear: both;"></div>

<?php } ?>

	<div class="profile_box_header">
		Media
<?php if ($_SESSION['username'] == $username) /*user's own profile*/ { ?>
		<span class="inline_button"> <a href="frame.php?page=myuploads">Edit</a> </span>
<?php } ?>
	</div>
	
	<div class="profile_box_border">
		<div class="padded_text">
<?php

	$index = 1;
	$itemCount = 0;

	OutputFiles($username, 'pictures');
	OutputFiles($username, 'music');
	OutputFiles($username, 'blog');

?>

<?php

	function OutputFiles($username, $type)
	{
		
		$site_root = "../";
		require_once $site_root . "common/gallery/Gallery_new.obj";
		include $site_root . "common/gallery/setupGallery.php"; //creates a $gallery object which we can use for table names and other specifics
		
		require_once "../common/PinSQL.obj";
		$pinSQL = new PinSQL();
		$pinSQL2 = new PinSQL();

		$pinSQL->Query("SELECT * FROM $gallery->dataTable WHERE artist='$username' ORDER BY name");

		global $index;
		global $itemCount;
		$totalRows = $pinSQL->GetNumRows();
		$thisRow = 0;
		
		while ( $row = $pinSQL->FetchNextRow() )
		{
			$itemCount++;
			$thisRow++;
			
			$totalratings = $pinSQL->GetMediaField( $gallery->dataTable, $row['id'], "totalratings" );
			$totalstars = $pinSQL->GetMediaField( $gallery->dataTable, $row['id'], "totalstars" );
			$averagestars = round($totalstars / $totalratings / 2, 0);
			
			$pinSQL2->Query("SELECT * FROM $gallery->commentsTable WHERE itemid=" . $row['id']);

			if ($type != "pictures") {
			
?>
		
			<img src="/img/icons/<?php echo $gallery->galleryItemName; ?>_sm.png" />
			<a href="/common/gallery/portal_<?php echo $type; ?>.php?dest=<?php echo $row['id']; ?>">
			<?php echo ($row['name']) ? $row['name'] : "(untitled)"; ?></a>
			
			<?php if ($averagestars) { ?><img src="/img/gauge_<?php echo $averagestars; ?>_sm.png" /><?php } ?>
			
			<?php if ($pinSQL2->GetNumRows()) { ?><span class="verysubtle"><?php echo $pinSQL2->GetNumRows(); ?> comment<?php if ($pinSQL2->GetNumRows() > 1) { echo "s"; } ?></span><?php } ?>

			<div class="horizontal_separation"></div>
	
<?php		} else { ?>

			<div style="width: 110px; margin-right: 5px; text-align: center; margin-bottom: 5px; float: left;">
				
				
				
				
				
				
				
				
				
				

<?php
	
		$picID = $row['id'];

		$imageSize = getimagesize("userData/" . $row['artist'] . "/pictures/" . $row['thumburl']);
		if (($imageSize[0] <= 110) AND ($imageSize[1] <= 96))
		{
			$newWidth = $imageSize[0];
			$newHeight = $imageSize[1];
		} else {
			$heightFactor = $imageSize[1] / $imageSize[0];
			$newWidth = 110;
			$newHeight = $newWidth * $heightFactor;
			
			if ($newHeight > 96)
			{
				$widthFactor = $imageSize[0] / $imageSize[1];
				$newHeight = 96;
				$newWidth = $newHeight * $widthFactor;
			}
		}

?>
		
			<a href="userData/<?php echo $row['artist'] . "/pictures/" . $row['filename']; ?>" class="highslide" onclick="return hs.expand(this)">
			    <img src="userData/<?php echo $row['artist'] . "/pictures/" . $row['thumburl']; ?>" width="<?php echo $newWidth; ?>" height="<?php echo $newHeight; ?>" border=0>
			</a>
			
			<div>
				<a href="/common/gallery/portal_<?php echo $type; ?>.php?dest=<?php echo $row['id']; ?>">			
				<?php echo ($row['name']) ? $row['name'] : "(untitled)"; ?>
				</a>
				
				<?php if ($pinSQL2->GetNumRows()) { ?>
					<div class="verysubtle">
						<?php if ($averagestars) { ?><img src="/img/gauge_<?php echo $averagestars; ?>_sm.png" /><?php } ?>
						<?php echo $pinSQL2->GetNumRows(); ?> comment<?php if ($pinSQL2->GetNumRows() > 1) { echo "s"; } ?>
					</div>
				<?php } ?>
			</div>
				
				
				
				
				
				
				
				
				
					
				
			
				
				
				
				
				
				
				
				
			</div>
			
			<?php if (($thisRow == $totalRows) OR ($thisRow % 2 == 0)) { ?>
			<div class="horizontal_separation" style="clear: both;" ></div>
			<?php } ?>

<?php 		}

		}
	}
	
?>

<?php if (!$itemCount) { echo ($firstname) ? $firstname : $username; ?>
 has not uploaded any media.
<?php } ?>
		</div>
	</div>
	
	<div class="horizontal_separation" style="clear: both;"></div>
	<div class="horizontal_separation" style="clear: both;"></div>
	
	<div class="profile_box_header">
		Buzz
<?php if ($_SESSION['username'] == $username) /*user's own profile*/ { ?>
		<span class="inline_button"> <a href="frame.php?page=profile&tab=buzz&user=<?php echo $_SESSION['username']; ?>">Edit</a> </span>
<?php } ?>
	</div>
	
	<div class="profile_box_border">
		<div class="padded_text">
			<img src="/img/arrow_white.gif" /><a href="frame.php?page=profile&tab=buzz&user=<?php echo $username; ?>&write=1">Write on <?php echo ($firstname) ? $firstname : $username; ?>'s buzz</a>
		
			<div class="horizontal_separation"></div>

<?php

	$site_root = "../";
	$showUser = $username;
	include ($site_root . "members/gen_buzz.php"); 

?>
		</div>
	</div>
	
</div>

	<div class="horizontal_separation" style="clear: both;"></div>
	<div class="horizontal_separation" style="clear: both;"></div>
	
	<img src="/img/copyright_footer_orange.png" />

	<div class="horizontal_separation" style="clear: both;"></div>
	<div class="horizontal_separation" style="clear: both;"></div>
	
</div>